const express = require("express");
const { login } = require("./modules/login");
const { register } = require("./modules/register");
const getUser = require("./modules/getUser");
const session = require("express-session")
const multer = require("multer");
const _upload = require("./modules/upload");
const setUser = require("./modules/setUser");

const app = express();

const upload = multer({ dest: "./upload" });
app.use(upload.any());

app.use(express.static("./www"));
app.use(express.static("./upload"));

app.use(express.urlencoded({extended: false}));

app.use(session({
    secret: '千锋H5',   // 加密信息，可以随便写
    resave: false,     // 强制保存session，默认为true，建议设置为false
    saveUninitialized: true,   // 强制将未初始化的session存储，默认为true，建议为true
    cookie: { maxAge: 1000 * 60 * 30 }    // 过期时间，毫秒数
}));

app.get("/login", login() );

app.post("/register", register("hello") );

app.get("/getUser", getUser() );

app.post("/upload", _upload() );

app.post("/setUser", setUser() );

app.listen(3000, ()=>{
    console.log("服务器开启成功,地址为: http://localhost:3000")
})
